home *** CD-ROM | disk | FTP | other *** search
/ IRIX Base Documentation 2001 May / SGI IRIX Base Documentation 2001 May.iso / usr / share / catman / u_man / cat3 / Tcl / cmdwrite.z / cmdwrite
Encoding:
Text File  |  1998-10-30  |  54.4 KB  |  859 lines

  1.  
  2.  
  3.  
  4. CCCCoooommmmmmmmaaaannnndddd WWWWrrrriiiittttiiiinnnngggg((((3333TTTTccccllll))))                                    CCCCoooommmmmmmmaaaannnndddd WWWWrrrriiiittttiiiinnnngggg((((3333TTTTccccllll))))
  5.  
  6.  
  7.  
  8. NNNNAAAAMMMMEEEE
  9.      TclCommandWriting - Writing C language extensions to Tcl.
  10.  
  11. OOOOVVVVEEEERRRRVVVVIIIIEEEEWWWW
  12.      This document is intended to help the programmer who wishes to extend Tcl
  13.      with C language routines.  It should also be useful to someone wishing to
  14.      add Tcl to an existing editor, communications program, window manager,
  15.      etc.  C programming information can also be found in the *._3 manual pages
  16.      in the _d_o_c directory of the Berkeley distribution, and in the *._3
  17.      manpages in the _m_a_n directory of Extended Tcl.
  18.  
  19. WWWWRRRRIIIITTTTIIIINNNNGGGG TTTTCCCCLLLL EEEEXXXXTTTTEEEENNNNSSSSIIIIOOOONNNNSSSS IIIINNNN CCCC
  20.      All C-based Tcl commands are called with four arguments: a client data
  21.      pointer, an interpreter pointer, an argument count and a pointer to an
  22.      array of pointers to character strings containing the Tcl arguments to
  23.      the command.
  24.  
  25.      A simple Tcl extension in C is now presented, and described below:
  26.  
  27.          #include "tcl.h"
  28.  
  29.          int App_EchoCmd(clientData, interp, argc, argv)
  30.              void       *clientData;
  31.              Tcl_Interp *interp;
  32.              int         argc;
  33.              char      **argv;
  34.          {
  35.                  int i;
  36.  
  37.                  for (i = 1; i < argc; i++) {
  38.                          printf("%s",argv[i]);
  39.                    if (i < argc - 1) printf(" ");
  40.                  }
  41.                  printf("\n");
  42.                  return TCL_OK;
  43.          }
  44.  
  45.      The client data pointer will be described later.
  46.  
  47.      The interpreter pointer is the ``key'' to an interpreter.  It is returned
  48.      by TTTTccccllll____CCCCrrrreeeeaaaatttteeeeIIIInnnntttteeeerrrrpppp and is used extensively within Tcl, and will be by
  49.      your C extensions.  The data structure pointed to by the interpreter
  50.      pointer, and all of the subordinate structures that branch off of it,
  51.      make up a Tcl interpreter, which includes all of the currently defined
  52.      procedures, commands, variables, arrays and the execution state of that
  53.      interpreter.  (For more information on creating and deleting
  54.      interpreters, please examine the CCCCrrrrttttIIIInnnntttteeeerrrrpppp(3) manpage in the Berkeley Tcl
  55.      distribution.  For information on creating interpreters that include the
  56.      commands provided by Extended Tcl, check out the TTTTccccllllXXXX____IIIInnnniiiitttt(3) manpage of
  57.      Extended Tcl.  For a manual page describing the user-visible fields of a
  58.      Tcl interpreter, please look at IIIInnnntttteeeerrrrpppp(3) in Berkeley Tcl.)
  59.  
  60.  
  61.  
  62.  
  63.                                                                         PPPPaaaaggggeeee 1111
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70. CCCCoooommmmmmmmaaaannnndddd WWWWrrrriiiittttiiiinnnngggg((((3333TTTTccccllll))))                                    CCCCoooommmmmmmmaaaannnndddd WWWWrrrriiiittttiiiinnnngggg((((3333TTTTccccllll))))
  71.  
  72.  
  73.  
  74.      The argument count and pointer to an array of pointers to textual
  75.      arguments is handled by your C code in the same manner that you would use
  76.      in writing a C _m_a_i_n function -- the argument count and array of pointers
  77.      works the same as in a C _m_a_i_n call; pointers to the arguments to the
  78.      function are contained in the _a_r_g_v array.  Similar to a C main, the first
  79.      argument (_a_r_g_v[_0]) is the name the routine was called as (in a main, the
  80.      name the program was invoked as).
  81.  
  82.      In the above example, all of the arguments are output with a space
  83.      between each one by looping through _a_r_g_v from one to the argument count,
  84.      _a_r_g_c, and a newline is output to terminate the line -- an ``echo''
  85.      command.
  86.  
  87.      All arguments from a Tcl call to a Tcl C extension are passed as strings.
  88.      If your C routine expects certain numeric arguments, your routine must
  89.      first convert them using the TTTTccccllll____GGGGeeeettttIIIInnnntttt or TTTTccccllll____GGGGeeeettttDDDDoooouuuubbbblllleeee function,
  90.      Extended Tcl's TTTTccccllll____GGGGeeeettttLLLLoooonnnngggg or TTTTccccllll____GGGGeeeettttUUUUnnnnssssiiiiggggnnnneeeedddd, or some other method of
  91.      your own devising.  Likewise for converting boolean values,
  92.      TTTTccccllll____GGGGeeeettttBBBBoooooooolllleeeeaaaannnn should be used.  These routines automatically leave an
  93.      appropriate error message in the Tcl interpreter's result buffer and
  94.      return TTTTCCCCLLLL____EEEERRRRRRRROOOORRRR if a conversion error occurs.   (For more information on
  95.      these routines, please look at the GGGGeeeettttIIIInnnntttt(3) manpage in the Berkeley Tcl
  96.      distribution.)
  97.  
  98.      Likewise, if you program produces a numeric result, it should return a
  99.      string equivalent to that numeric value.  A common way of doing this is
  100.      something like...
  101.  
  102.           sprintf(interp->result, "%ld", result);
  103.  
  104.      Writing results directly into the interpreter's result buffer is only
  105.      good for relatively short results.  Tcl has a function, TTTTccccllll____SSSSeeeettttRRRReeeessssuuuulllltttt,
  106.      which provides the ability for your C extensions to return very large
  107.      strings to Tcl, with the ability to tell the interpreter whether it
  108.      ``owns'' the string (meaning that Tcl should delete the string when it's
  109.      done with it), that the string is likely to be changed or overwritten
  110.      soon (meaning that Tcl should make a copy of the string right away), or
  111.      that the string won't change (so Tcl can use the string as is and not
  112.      worry about it).  Understanding how results are passed back to Tcl is
  113.      essential to the C extension writer.  Please study the SSSSeeeettttRRRReeeessssuuuulllltttt(3)
  114.      manual page in the Tcl distribution.
  115.  
  116.      Sophisticated commands should verify their arguments whenever possible,
  117.      both by examining the argument count, by verifying that numeric fields
  118.      are really numeric, that values are in range (when their ranges are
  119.      known), and so forth.
  120.  
  121.      Tcl is designed to be as bullet-proof as possible, in the sense that no
  122.      Tcl program should be able to cause Tcl to dump core.  Please carry this
  123.      notion forward with your C extensions by validating arguments as above.
  124.  
  125.  
  126.  
  127.  
  128.  
  129.                                                                         PPPPaaaaggggeeee 2222
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136. CCCCoooommmmmmmmaaaannnndddd WWWWrrrriiiittttiiiinnnngggg((((3333TTTTccccllll))))                                    CCCCoooommmmmmmmaaaannnndddd WWWWrrrriiiittttiiiinnnngggg((((3333TTTTccccllll))))
  137.  
  138.  
  139.  
  140. AAAANNNNOOOOTTTTHHHHEEEERRRR CCCC EEEEXXXXTTTTEEEENNNNSSSSIIIIOOOONNNN ---- TTTTHHHHEEEE MMMMAAAAXXXX
  141.      In the command below, two or more arguments are compared and the one with
  142.      the maximum value is returned, if all goes well.  It is an error if there
  143.      are fewer than three arguments (the pointer to the ``max'' command text
  144.      itself, _a_r_g_v[_0], and pointers to at least two arguments to compare the
  145.      values of).
  146.  
  147.      This routine also shows the use of the programmer labor-saving
  148.      TTTTccccllll____AAAAppppppppeeeennnnddddRRRReeeessssuuuulllltttt routine.  See the Tcl manual page, SSSSeeeettttRRRReeeessssuuuulllltttt(3), for
  149.      details.  Also examine the calls TTTTccccllll____AAAAddddddddEEEErrrrrrrroooorrrrIIIInnnnffffoooo, TTTTccccllll____SSSSeeeettttEEEErrrrrrrroooorrrrCCCCooooddddeeee and
  150.      TTTTccccllll____PPPPoooossssiiiixxxxEEEErrrrrrrroooorrrr documented in the Tcl manual page AAAAddddddddEEEErrrrrrrrIIIInnnnffffoooo(3).
  151.  
  152.          int
  153.          Tcl_MaxCmd (clientData, interp, argc, argv)
  154.              char       *clientData;
  155.              Tcl_Interp *interp;
  156.              int         argc;
  157.              char      **argv;
  158.          {
  159.              int maxVal = MININT;
  160.              int maxIdx = 1;
  161.              int value, idx;
  162.  
  163.  
  164.              if (argc < 3) {
  165.                  Tcl_AppendResult (interp, "bad # arg: ", argv[0],
  166.                                    " num1 num2 [..numN]", (char *)NULL);
  167.                  return TCL_ERROR;
  168.              }
  169.  
  170.              for (idx = 1; idx < argc; idx++) {
  171.                  if (Tcl_GetInt (argv[idx], 10, &Value) != TCL_OK)
  172.                      return TCL_ERROR;
  173.  
  174.                  if (value > maxVal) {
  175.                      maxVal = value;
  176.                      maxIdx = idx;
  177.                  }
  178.              }
  179.              Tcl_SetResult (interp, argv [maxIdx], TCL_VOLATILE);
  180.              return TCL_OK;
  181.          }
  182.  
  183.      When Tcl-callable functions complete, they should normally return TTTTCCCCLLLL____OOOOKKKK
  184.      or TTTTCCCCLLLL____EEEERRRRRRRROOOORRRR.  TTTTCCCCLLLL____OOOOKKKK is returned when the command succeeded and
  185.      TTTTCCCCLLLL____EEEERRRRRRRROOOORRRR is returned when the command has failed in some abnormal way.
  186.      TTTTCCCCLLLL____EEEERRRRRRRROOOORRRR should be returned for all syntax errors, non-numeric values
  187.      (when numeric ones were expected), and so forth.  Less clear in some
  188.      cases is whether Tcl errors should be returned or whether a function
  189.      should just return a status value.  For example, end-of-file during a
  190.      _g_e_t_s returns a status, but _o_p_e_n returns an error if the open fails.
  191.      Errors can be caught from Tcl programs using the _c_a_t_c_h command.  (See
  192.  
  193.  
  194.  
  195.                                                                         PPPPaaaaggggeeee 3333
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202. CCCCoooommmmmmmmaaaannnndddd WWWWrrrriiiittttiiiinnnngggg((((3333TTTTccccllll))))                                    CCCCoooommmmmmmmaaaannnndddd WWWWrrrriiiittttiiiinnnngggg((((3333TTTTccccllll))))
  203.  
  204.  
  205.  
  206.      Tcl's ccccaaaattttcccchhhh(n) and eeeerrrrrrrroooorrrr(n) manual pages.)
  207.  
  208.      Less common return values are TTTTCCCCLLLL____RRRREEEETTTTUUUURRRRNNNN, TTTTCCCCLLLL____BBBBRRRREEEEAAAAKKKK and TTTTCCCCLLLL____CCCCOOOONNNNTTTTIIIINNNNUUUUEEEE.
  209.      These are used if you are adding new control and/or looping structures to
  210.      Tcl.  To see these values in action, examine the source code to Tcl's
  211.      _w_h_i_l_e, _f_o_r and _i_f, and Extended Tcl's _l_o_o_p commands.
  212.  
  213.      Note the call to _T_c_l__S_e_t_R_e_s_u_l_t in the above command to set the return
  214.      value to Tcl.  TTTTCCCCLLLL____VVVVOOOOLLLLAAAATTTTIIIILLLLEEEE is used because the memory containing the
  215.      result will be freed upon the function's return.
  216.  
  217.  
  218. AAAANNNNOOOOTTTTHHHHEEEERRRR CCCC EEEEXXXXTTTTEEEENNNNSSSSIIIIOOOONNNN ---- TTTTHHHHEEEE LLLLRRRREEEEVVVVEEEERRRRSSSSEEEE
  219.      In the command below, one list is passed as an argument, and a list
  220.      containing all of the elements of the list in reverse order is returned.
  221.      It is an error if anything other than two arguments are passed (the
  222.      pointer to the ``lreverse'' command text itself, _a_r_g_v[_0], and a pointer
  223.      to the list to reverse.
  224.  
  225.      Once _l_r_e_v_e_r_s_e has determined that it has received the correct number of
  226.      arguments, TTTTccccllll____SSSSpppplllliiiittttLLLLiiiisssstttt is called to break the list into an _a_r_g_c and
  227.      _a_r_g_v array of pointers.
  228.  
  229.      _l_r_e_v_e_r_s_e then operates on the array of pointers, swapping them from
  230.      lowest to highest, second-lowest to second-highest, and so forth.
  231.  
  232.      Finally TTTTccccllll____MMMMeeeerrrrggggeeee is calleds to create a single new string containing the
  233.      reversed list and it is set as the result via TTTTccccllll____SSSSeeeettttRRRReeeessssuuuulllltttt.  Note that
  234.      TTTTCCCCLLLL____DDDDYYYYNNNNAAAAMMMMIIIICCCC is used to tell TTTTccccllll____SSSSeeeettttRRRReeeessssuuuulllltttt that it now owns the string and
  235.      it is up to Tcl to free the string when it is done with it.
  236.  
  237.      Note that it _i_s safe to play around with the _a_r_g_v list like this, and
  238.      that a single call to cccckkkkffffrrrreeeeeeee can be made to free all the data returned by
  239.      TTTTccccllll____SSSSpppplllliiiittttLLLLiiiisssstttt in this manner.
  240.  
  241.      int
  242.      Tcl_LreverseCmd(notUsed, interp, argc, argv)
  243.          ClientData notUsed;            /* Not used. */
  244.          Tcl_Interp *interp;            /* Current interpreter. */
  245.          int argc;                 /* Number of arguments. */
  246.          char **argv;              /* Argument strings. */
  247.      {
  248.          int listArgc, lowListIndex, hiListIndex;
  249.          char **listArgv;
  250.          char *temp, *resultList;
  251.  
  252.          if (argc != 2) {
  253.           Tcl_AppendResult(interp, "wrong # args: should be
  254.                " list
  255.           return TCL_ERROR;
  256.          }
  257.  
  258.  
  259.  
  260.  
  261.                                                                         PPPPaaaaggggeeee 4444
  262.  
  263.  
  264.  
  265.  
  266.  
  267.  
  268. CCCCoooommmmmmmmaaaannnndddd WWWWrrrriiiittttiiiinnnngggg((((3333TTTTccccllll))))                                    CCCCoooommmmmmmmaaaannnndddd WWWWrrrriiiittttiiiinnnngggg((((3333TTTTccccllll))))
  269.  
  270.  
  271.  
  272.          if (Tcl_SplitList(interp, argv[1], &listArgc, &listArgv) != TCL_OK) {
  273.           return TCL_ERROR;
  274.          }
  275.          for (lowListIndex = 0, hiListIndex = listArgc;
  276.            --hiListIndex > lowListIndex; lowListIndex++) {
  277.           temp = listArgv[lowListIndex];
  278.           listArgv[lowListIndex] = listArgv[hiListIndex];
  279.           listArgv[hiListIndex] = temp;
  280.          }
  281.          resultList = Tcl_Merge (listArgc, listArgv);
  282.          ckfree (listArgv);
  283.          Tcl_SetResult (interp, resultList, TCL_DYNAMIC);
  284.          return TCL_OK;
  285.      }
  286.  
  287. IIIINNNNSSSSTTTTAAAALLLLLLLLIIIINNNNGGGG YYYYOOOOUUUURRRR CCCCOOOOMMMMMMMMAAAANNNNDDDD
  288.      To install your command into Tcl you must call TTTTccccllll____CCCCrrrreeeeaaaatttteeeeCCCCoooommmmmmmmaaaannnndddd, passing
  289.      it the pointer to the interpreter you want to install the command into,
  290.      the name of the command, a pointer to the C function that implements the
  291.      command, a client data pointer, and a pointer to an optional callback
  292.      routine.
  293.  
  294.      The client data pointer and the callback routine will be described later.
  295.  
  296.      For example, for the max function above (which, incidentally, comes from
  297.      TclX's tclXmath.c in the _T_c_l_X_7._4/_s_r_c directory):
  298.  
  299.          Tcl_CreateCommand (interp, "max", Tcl_MaxCmd, (ClientData)NULL,
  300.                            (void (*)())NULL);
  301.  
  302.      In the above example, the max function is added to the specified
  303.      interpreter.  The client data pointer and callback function pointer are
  304.      NULL.  (For complete information on TTTTccccllll____CCCCrrrreeeeaaaatttteeeeCCCCoooommmmmmmmaaaannnndddd and its companion
  305.      routine, TTTTccccllll____CCCCoooommmmmmmmaaaannnnddddIIIInnnnffffoooo, please examine the CCCCrrrrttttCCCCoooommmmmmmmaaaannnndddd(3) command page
  306.      in the Berkeley Tcl distribution.)
  307.  
  308. DDDDYYYYNNNNAAAAMMMMIIIICCCC SSSSTTTTRRRRIIIINNNNGGGGSSSS
  309.      _D_y_n_a_m_i_c _s_t_r_i_n_g_s are an important abstraction that first became available
  310.      with Tcl 7.0.  Dynamic strings, or _D_S_t_r_i_n_g_s, provide a way to build up
  311.      arbitrarily long strings through a repeated process of appending
  312.      information to them.  DStrings reduce the amount of allocating and
  313.      copying required to add information to a string.  Further, they simplify
  314.      the process of doing so.  For complete information on dynamic strings,
  315.      please examine the DDDDSSSSttttrrrriiiinnnngggg(3) manual page in the Berkeley Tcl
  316.      distribution.
  317.  
  318. CCCCLLLLIIIIEEEENNNNTTTT DDDDAAAATTTTAAAA
  319.      The client data pointer provides a means for Tcl commands to have data
  320.      associated with them that is not global to the C program nor included in
  321.      the Tcl core.  Client data is essential in a multi-interpreter
  322.      environment (where a single program has created and is making use of
  323.      multiple Tcl interpreters) for the C routines to maintain any permanent
  324.  
  325.  
  326.  
  327.                                                                         PPPPaaaaggggeeee 5555
  328.  
  329.  
  330.  
  331.  
  332.  
  333.  
  334. CCCCoooommmmmmmmaaaannnndddd WWWWrrrriiiittttiiiinnnngggg((((3333TTTTccccllll))))                                    CCCCoooommmmmmmmaaaannnndddd WWWWrrrriiiittttiiiinnnngggg((((3333TTTTccccllll))))
  335.  
  336.  
  337.  
  338.      data they need on a per-interpreter basis.  Otherwise there would be
  339.      reentrancy problems.  Tcl solves this through the client data mechanism.
  340.      When you are about to call TTTTccccllll____CCCCrrrreeeeaaaatttteeeeCCCCoooommmmmmmmaaaannnndddd to add a new command to an
  341.      interpreter, if that command needs to keep some read/write data across
  342.      invocations, you should allocate the space, preferably using cccckkkkaaaalllllllloooocccc,
  343.      then pass the address of that space as the ClientData pointer to
  344.      TTTTccccllll____CCCCrrrreeeeaaaatttteeeeCCCCoooommmmmmmmaaaannnndddd.
  345.  
  346.      When your command is called from Tcl, the ClientData pointer you gave to
  347.      TTTTccccllll____CCCCrrrreeeeaaaatttteeeeCCCCoooommmmmmmmaaaannnndddd when you added the command to that interpreter is
  348.      passed to your C routine through the ClientData pointer calling argument.
  349.  
  350.      Commands that need to share this data with one another can do so by using
  351.      the same ClientData pointer when the commands are added.
  352.  
  353.      It is important to note that the Tcl extensions in the _t_c_l_X_7._4/_s_r_c
  354.      directory have had all of their data set up in this way.  Since release
  355.      6.2, Extended Tcl has supported multiple interpreters within one
  356.      invocation of Tcl.
  357.  
  358. TTTTHHHHEEEEOOOORRRRYYYY OOOOFFFF HHHHAAAANNNNDDDDLLLLEEEESSSS
  359.      Sometimes you need to have a data element that isn't readily
  360.      representable as a string within Tcl, for example a pointer to a complex
  361.      C data structure.  It is not a good idea to try to pass pointers around
  362.      within Tcl as strings by converting them to and from hex or integer
  363.      representations, for example.  It is too easy to mess one up, and the
  364.      likely outcome of doing that is a core dump.
  365.  
  366.      Instead we have developed and made use of the concept of _h_a_n_d_l_e_s.
  367.      Handles are identifiers a C extension can pass to, and accept from, Tcl
  368.      to make the transition between what your C code knows something as and
  369.      what name Tcl knows it by to be as safe and painless as possible. For
  370.      example, the stdio package included in Tcl uses file handles.  When you
  371.      open a file from Tcl, a handle is returned of the form ffffiiiilllleeee_n where _n is a
  372.      file number.  When you pass the file handle back to _p_u_t_s, _g_e_t_s, _s_e_e_k,
  373.      _f_l_u_s_h and so forth, they validate the file handle by checking the the
  374.      ffffiiiilllleeee text is present, then converting the file number to an integer that
  375.      they use to look into a data structure of pointers to Tcl open file
  376.      structures, which contain a Unix file descriptor, flags indicating
  377.      whether or not the file is currently open, whether the file is a file or
  378.      a pipe and so forth.
  379.  
  380.      Handles have proven so useful that, as of release 6.1a, general support
  381.      has been added for them.  If you need a similar capability, it would be
  382.      best to use the handle routines, documented in HHHHaaaannnnddddlllleeeessss(3) in Extended
  383.      Tcl.  We recommend that you use a unique-to-your-package textual handle
  384.      coupled with a specific identifier and let the handle management routines
  385.      validate it when it's passed back.  It is much easier to track down a bug
  386.      with an implicated handle named something like ffffiiiilllleeee4444 or bbbbiiiittttmmmmaaaapppp6666 than just
  387.      6666.
  388.  
  389.  
  390.  
  391.  
  392.  
  393.                                                                         PPPPaaaaggggeeee 6666
  394.  
  395.  
  396.  
  397.  
  398.  
  399.  
  400. CCCCoooommmmmmmmaaaannnndddd WWWWrrrriiiittttiiiinnnngggg((((3333TTTTccccllll))))                                    CCCCoooommmmmmmmaaaannnndddd WWWWrrrriiiittttiiiinnnngggg((((3333TTTTccccllll))))
  401.  
  402.  
  403.  
  404. TTTTRRRRAAAACCCCKKKKIIIINNNNGGGG MMMMEEEEMMMMOOOORRRRYYYY CCCCOOOORRRRRRRRUUUUPPPPTTTTIIIIOOOONNNN PPPPRRRROOOOBBBBLLLLEEEEMMMMSSSS
  405.      Occasionally you may write code that scribbles past the end of an
  406.      allocated piece of memory.  The memory debugging routines included in Tcl
  407.      can help find these problems.  See _M_e_m_o_r_y(_T_C_L) for details.
  408.  
  409. IIIINNNNSSSSTTTTAAAALLLLLLLLIIIINNNNGGGG YYYYOOOOUUUURRRR EEEEXXXXTTTTEEEENNNNSSSSIIIIOOOONNNNSSSS IIIINNNNTTTTOOOO EEEEXXXXTTTTEEEENNNNDDDDEEEEDDDD TTTTCCCCLLLL
  410.      To add your extensions to Extended Tcl, you must compile them and cause
  411.      them to be linked with TclX.  For the routines to be linked into the ttttccccllll
  412.      and wwwwiiiisssshhhhxxxx executables, they must be referenced (directly or indirectly)
  413.      from TclX.  For these extensions to be visible as Tcl commands, they must
  414.      be installed into Tcl with TTTTccccllll____CCCCrrrreeeeaaaatttteeeeCCCCoooommmmmmmmaaaannnndddd.
  415.  
  416.      Application-specific startup is accomplished by creating or editing the
  417.      _T_c_l__A_p_p_I_n_i_t function.  In _T_c_l__A_p_p_I_n_i_t you should add a call to an
  418.      application-specific init function which you create.  This function
  419.      should take the address of the interpreter it should install its commands
  420.      into, and it should install those commands with TTTTccccllll____CCCCrrrreeeeaaaatttteeeeCCCCoooommmmmmmmaaaannnndddd and do
  421.      any other application-specific startup that is necessary.
  422.  
  423.      The naming convention for application startup routines is AAAApppppppp____IIIInnnniiiitttt, where
  424.      _A_p_p is the name of your application.  For example, to add an application
  425.      named _c_u_t_e one would create a _C_u_t_e__I_n_i_t routine that expected a
  426.      TTTTccccllll____IIIInnnntttteeeerrrrpppp pointer as an argument, and add the following code to
  427.      _T_c_l__A_p_p_I_n_i_t:
  428.  
  429.          if (Cute_Init (interp) == TCL_ERROR) {
  430.           return TCL_ERROR;
  431.          }
  432.  
  433.      As you can guess from the above example, if your init routine is unable
  434.      to initialize, it should use TTTTccccllll____AAAAppppppppeeeennnnddddRRRReeeessssuuuulllltttt to provide some kind of
  435.      useful error message back to TclX, then return TTTTCCCCLLLL____EEEERRRRRRRROOOORRRR to indicate that
  436.      an error occurred.  If the routine executed successfully, it should
  437.      return TTTTCCCCLLLL____OOOOKKKK.
  438.  
  439.      When you examine _T_c_l__A_p_p_I_n_i_t, note that there is one call already there
  440.      to install an application -- the call to _T_c_l_X__I_n_i_t installs Extended Tcl
  441.      into the Tcl core.
  442.  
  443.  
  444. MMMMAAAAKKKKIIIINNNNGGGG AAAAPPPPPPPPLLLLIIIICCCCAAAATTTTIIIIOOOONNNN IIIINNNNFFFFOOOORRRRMMMMAAAATTTTIIIIOOOONNNN VVVVIIIISSSSIIIIBBBBLLLLEEEE FFFFRRRROOOOMMMM EEEEXXXXTTTTEEEENNNNDDDDEEEEDDDD
  445.      TclX's iiiinnnnffffooooxxxx command can return several pieces of information relevant to
  446.      Extended Tcl, including the application's name, descriptive name, patch
  447.      level and version.  Your application's startup can set these variables to
  448.      application-specific values.  If it doesn't, they are given default
  449.      values for Extended Tcl.
  450.  
  451.      To set these values, first be sure that you include either ttttccccllllEEEExxxxtttteeeennnndddd....hhhh or
  452.      ttttccccllllEEEExxxxttttddddIIIInnnntttt....hhhh from the source file that defines your init routine.  This
  453.      will create external declarations for the variables.  Then, set the
  454.      variables in your init route, for example:
  455.  
  456.  
  457.  
  458.  
  459.                                                                         PPPPaaaaggggeeee 7777
  460.  
  461.  
  462.  
  463.  
  464.  
  465.  
  466. CCCCoooommmmmmmmaaaannnndddd WWWWrrrriiiittttiiiinnnngggg((((3333TTTTccccllll))))                                    CCCCoooommmmmmmmaaaannnndddd WWWWrrrriiiittttiiiinnnngggg((((3333TTTTccccllll))))
  467.  
  468.  
  469.  
  470.          tclAppName = "cute";
  471.          tclAppLongName = "Call Unix/Tcl Environment";
  472.          tclAppVersion = "2.1";
  473.  
  474.      Note that the default values are set by _T_c_l_X__I_n_i_t, so if you wish to
  475.      override them, you must call your init routine in _T_c_l__A_p_p_I_n_i_t after its
  476.      call to _T_c_l_X__I_n_i_t.
  477.  
  478. EEEEXXXXTTTTEEEENNNNDDDDEEEEDDDD TTTTCCCCLLLL EEEEXXXXIIIITTTT
  479.      When Extended Tcl exits, TTTTccccllll____DDDDeeeelllleeeetttteeeeIIIInnnntttteeeerrrrpppp may be called to free memory
  480.      used by Tcl -- normally, this is only called if TTTTCCCCLLLL____MMMMEEEEMMMM____DDDDEEEEBBBBUUUUGGGG was
  481.      defined, since Unix will return all of the allocated memory back to the
  482.      system, anyway.  If TTTTCCCCLLLL____MMMMEEEEMMMM____DDDDEEEEBBBBUUUUGGGG was defined, it is called so that any
  483.      memory that was allocated without ever being freed can be detected.  This
  484.      greatly reduces the amount of work to detect and track down memory leaks,
  485.      a situation where some piece of your code allocates memory repeatedly
  486.      without ever freeing it, or without always freeing it.
  487.  
  488.      It is often necessary for an application to perform special cleanup
  489.      functions upon the deletion of an interpreter as well.  To facilitate
  490.      this activity, Tcl provides the ability to perform a function callback
  491.      when an interpreter is deleted.  To arrange for a C function to be called
  492.      when the interpreter is deleted, call TTTTccccllll____CCCCaaaallllllllWWWWhhhheeeennnnDDDDeeeelllleeeetttteeeedddd from your
  493.      application initialization routine.  For details on how to use this
  494.      function, read the CCCCaaaallllllllDDDDeeeellll(3) manual page that ships with Berkeley Tcl.
  495.  
  496. EEEEXXXXEEEECCCCUUUUTTTTIIIINNNNGGGG TTTTCCCCLLLL CCCCOOOODDDDEEEE FFFFRRRROOOOMMMM YYYYOOOOUUUURRRR CCCC
  497.      Suppose you are in the middle of coding a C extension and you realize
  498.      that you need some operation performed, one that would be simple from Tcl
  499.      but possibly excruciating to do directly in C.  Tcl provides the
  500.      TTTTccccllll____EEEEvvvvaaaallll, TTTTccccllll____VVVVaaaarrrrEEEEvvvvaaaallll, TTTTccccllll____EEEEvvvvaaaallllFFFFiiiilllleeee and TTTTccccllll____GGGGlllloooobbbbaaaallllEEEEvvvvaaaallll functions for the
  501.      purpose of executing Tcl code from within a C extension.  The results of
  502.      the call will be in iiiinnnntttteeeerrrrpppp---->>>>rrrreeeessssuuuulllltttt.  For more information please consult
  503.      the EEEEvvvvaaaallll(3) manual page within the Berkely Tcl distribution.
  504.  
  505. AAAACCCCCCCCEEEESSSSSSSSIIIINNNNGGGG TTTTCCCCLLLL VVVVAAAARRRRIIIIAAAABBBBLLLLEEEESSSS AAAANNNNDDDD AAAARRRRRRRRAAAAYYYYSSSS FFFFRRRROOOOMMMM
  506.      Tcl variables and arrays can be read from a C extension through the
  507.      TTTTccccllll____GGGGeeeettttVVVVaaaarrrr and TTTTccccllll____GGGGeeeettttVVVVaaaarrrr2222 functions, and set from C extensions through
  508.      the TTTTccccllll____SSSSeeeettttVVVVaaaarrrr and TTTTccccllll____SSSSeeeettttVVVVaaaarrrr2222 functions.  They can also be unset via the
  509.      TTTTccccllll____UUUUnnnnsssseeeettttVVVVaaaarrrr and TTTTccccllll____UUUUnnnnsssseeeettttVVVVaaaarrrr2222 functions.  For complete information on
  510.      these functions, please refer to the SSSSeeeettttVVVVaaaarrrr(3) manual page in the _d_o_c
  511.      directory of the Berkeley Tcl distribution.
  512.  
  513. LLLLIIIINNNNKKKKIIIINNNNGGGG TTTTCCCCLLLL VVVVAAAARRRRIIIIAAAABBBBLLLLEEEESSSS TTTTOOOO CCCC VVVVAAAARRRRIIIIAAAABBBBLLLLEEEESSSS
  514.      TTTTccccllll____LLLLiiiinnnnkkkkVVVVaaaarrrr and TTTTccccllll____UUUUnnnnlllliiiinnnnkkkkVVVVaaaarrrr can be used to automatically keep Tcl
  515.      variables synchronized with corresponding C variables.  Once a Tcl
  516.      variable has been linked to a C variable with TTTTccccllll____LLLLiiiinnnnkkkkVVVVaaaarrrr, anytime the
  517.      Tcl variable is read the value of the C variable will be returned, and
  518.      when the Tcl variable is written, the C variable will be updated with the
  519.      new value.
  520.  
  521.  
  522.  
  523.  
  524.  
  525.                                                                         PPPPaaaaggggeeee 8888
  526.  
  527.  
  528.  
  529.  
  530.  
  531.  
  532. CCCCoooommmmmmmmaaaannnndddd WWWWrrrriiiittttiiiinnnngggg((((3333TTTTccccllll))))                                    CCCCoooommmmmmmmaaaannnndddd WWWWrrrriiiittttiiiinnnngggg((((3333TTTTccccllll))))
  533.  
  534.  
  535.  
  536.      TTTTccccllll____LLLLiiiinnnnkkkkVVVVaaaarrrr uses variable traces to keep the Tcl variable named by
  537.      _v_a_r_N_a_m_e in sync with the C variable at the address given by _a_d_d_r.
  538.  
  539.      Whenever the Tcl variable is read the value of the C variable will be
  540.      returned, and whenever the Tcl variable is written the C variable will be
  541.      updated to have the same value.
  542.  
  543.      _I_n_t, _d_o_u_b_l_e, _b_o_o_l_e_a_n and _c_h_a_r * variables are supported.  For more
  544.      information, please examine the LLLLiiiinnnnkkkkVVVVaaaarrrr(3) manual page in the Berkeley
  545.      Tcl distribution.
  546.  
  547. AAAADDDDDDDDIIIINNNNGGGG NNNNEEEEWWWW MMMMAAAATTTTHHHH FFFFUUUUNNNNCCCCTTTTIIIIOOOONNNNSSSS TTTTOOOO TTTTCCCCLLLL
  548.      As of Tcl version 7.0, math functions such as _s_i_n, _c_o_s, etc, are directly
  549.      supported within Tcl expressions.  These obsolete the Extended Tcl
  550.      commands that provided explicit calls for these functions for many
  551.      releases.
  552.  
  553.      New math functions can be added to Tcl, or existing math functions can be
  554.      replaced, by calling TTTTccccllll____CCCCrrrreeeeaaaatttteeeeMMMMaaaatttthhhhFFFFuuuunnnncccc.
  555.  
  556.      For more information on adding math functions, please examine the
  557.      CCCCrrrrttttMMMMaaaatttthhhhFFFFnnnncccc(3) manual page in the Berkeley Tcl distribution.
  558.  
  559. PPPPEEEERRRRFFFFOOOORRRRMMMMIIIINNNNGGGG TTTTIIIILLLLDDDDEEEE SSSSUUUUBBBBSSSSTTTTIIIITTTTUUUUTTTTIIIIOOOONNNNSSSS OOOONNNN FFFFIIIILLLLEEEENNNNAAAAMMMMEEEESSSS
  560.      The TTTTccccllll____TTTTiiiillllddddeeeeSSSSuuuubbbbsssstttt function is available to C extension writers to
  561.      perform tilde substitutions on filenames.  If the name starts with a
  562.      ``~'' character, the function returns a new string where the name is
  563.      replaced with the home directory of the given user.  For more information
  564.      please consult the TTTTiiiillllddddeeeeSSSSuuuubbbbsssstttt(3) manual page in the Berkeley Tcl
  565.      distribution.
  566.  
  567. SSSSEEEETTTTTTTTIIIINNNNGGGG TTTTHHHHEEEE RRRREEEECCCCUUUURRRRSSSSIIIIOOOONNNN LLLLIIIIMMMMIIIITTTT
  568.      Tcl has a preset recursion limit that limits the maximum allowable
  569.      nesting depth of calls within an interpreter.  This is useful for
  570.      detecting infinite recursions before other limits such as the process
  571.      memory limit or, worse, available swap space on the system, are exceeded.
  572.  
  573.      The default limit is just a guess, however, and applications that make
  574.      heavy use of recursion may need to call TTTTccccllll____SSSSeeeettttRRRReeeeccccuuuurrrrssssiiiioooonnnnLLLLiiiimmmmiiiitttt to raise
  575.      this limit.  For more information, please consult the SSSSeeeettttRRRReeeeccccLLLLmmmmtttt(3) manual
  576.      page in the Berkeley Tcl distribution.
  577.  
  578. HHHHAAAANNNNDDDDLLLLIIIINNNNGGGG SSSSIIIIGGGGNNNNAAAALLLLSSSS FFFFRRRROOOOMMMM TTTTCCCCLLLL EEEEXXXXTTTTEEEENNNNSSSSIIIIOOOONNNNSSSS
  579.      If an event such as a signal occurs while a Tcl script is being executed,
  580.      it isn't safe to do much in the signal handling routine -- the Tcl
  581.      environment cannot be safely manipulated at this point because it could
  582.      be in the middle of some operation, such as updating pointers, leaving
  583.      the interpreter in an unreliable state.
  584.  
  585.      The only safe approach is to set a flag indicating that the event
  586.      occurred, then handle the event later when the interpreter has returned
  587.      to a safe state, such as after the current Tcl command completes.
  588.  
  589.  
  590.  
  591.                                                                         PPPPaaaaggggeeee 9999
  592.  
  593.  
  594.  
  595.  
  596.  
  597.  
  598. CCCCoooommmmmmmmaaaannnndddd WWWWrrrriiiittttiiiinnnngggg((((3333TTTTccccllll))))                                    CCCCoooommmmmmmmaaaannnndddd WWWWrrrriiiittttiiiinnnngggg((((3333TTTTccccllll))))
  599.  
  600.  
  601.  
  602.      The TTTTccccllll____AAAAssssyyyynnnnccccCCCCrrrreeeeaaaatttteeee, TTTTccccllll____AAAAssssyyyynnnnccccMMMMaaaarrrrkkkk, TTTTccccllll____AAAAssssyyyynnnnccccIIIInnnnvvvvooookkkkeeee, and TTTTccccllll____AAAAssssyyyynnnnccccDDDDeeeelllleeeetttteeee
  603.      functions provide a safe mechanism for dealing with signals and other
  604.      asynchronous events.  For more information on how to use this capability,
  605.      please refer to the AAAAssssyyyynnnncccc(3) manual page in the Berkeley Tcl
  606.      distribution.
  607.  
  608.  
  609. PPPPAAAARRRRSSSSIIIINNNNGGGG BBBBAAAACCCCKKKKSSSSLLLLAAAASSSSHHHH SSSSEEEEQQQQUUUUEEEENNNNCCCCEEEESSSS
  610.      The TTTTccccllll____BBBBaaaacccckkkkssssllllaaaasssshhhh function is called to parse Tcl backslash sequences.
  611.      These backslash sequences are the usual sort that you see in the C
  612.      programming language, such as \\\\nnnn for newline, \\\\rrrr for return, and so
  613.      forth.  TTTTccccllll____BBBBaaaacccckkkkssssllllaaaasssshhhh parses a single backslash sequence and returns a
  614.      single character corresponding to the backslash sequence.
  615.  
  616.      For more info on this call, look at the BBBBaaaacccckkkkssssllllaaaasssshhhh(3) manual page in the
  617.      Berkeley Tcl distribution.  For information on the valid backslash
  618.      sequences, consult the summary of Tcl language syntax, TTTTccccllll(n) in the same
  619.      distribution.
  620.  
  621. HHHHAAAASSSSHHHH TTTTAAAABBBBLLLLEEEESSSS
  622.      _H_a_s_h _t_a_b_l_e_s provide Tcl with a high-performance facility for looking up
  623.      and managing key-value pairs located and maintained in memory.  Tcl uses
  624.      hash tables internally to locate procedure definitions, Tcl variables,
  625.      array elements, file handles and so forth.  Tcl makes the hash table
  626.      functions accessible to C extension writers as well.
  627.  
  628.      Hash tables grow automatically to maintain efficiency, rather than
  629.      exposing the table size to the programmer at allocation time, which would
  630.      needlessy add complexity to Tcl and would be prone to inefficiency due to
  631.      the need to guess the number of items that will go into the table, and
  632.      the seemingly inevitable growth in amount of data processed per run over
  633.      the life of the program.
  634.  
  635.      For more information on hash tables, please consult the HHHHaaaasssshhhh(3) manual
  636.      page in the Berkeley Tcl distribution.
  637.  
  638. TTTTRRRRAAAACCCCIIIINNNNGGGG VVVVAAAARRRRIIIIAAAABBBBLLLLEEEE AAAACCCCCCCCEEEESSSSSSSSEEEESSSS
  639.      The C extension writer can arrange to have a C routine called whenever a
  640.      Tcl variable is read, written, or unset.  Variable traces are the
  641.      mechanism by which Tk toolkit widgets such as radio and checkbuttons,
  642.      messages and so forth update without Tcl programmer intervention when
  643.      their data variables are changed.  They are also used by the routine that
  644.      links Tcl and C variables, TTTTccccllll____LLLLiiiinnnnkkkkVVVVaaaarrrr, described above.
  645.  
  646.      TTTTccccllll____TTTTrrrraaaacccceeeeVVVVaaaarrrr is called to establish a variable trace.  Entire arrays and
  647.      individual array elements can be traced as well.  If the programmer
  648.      already has an array name in one string and a variable name in another,
  649.      TTTTccccllll____TTTTrrrraaaacccceeeeVVVVaaaarrrr2222 can be called.  Calls are also available to request
  650.      information about traces and to delete them.
  651.  
  652.  
  653.  
  654.  
  655.  
  656.  
  657.                                                                        PPPPaaaaggggeeee 11110000
  658.  
  659.  
  660.  
  661.  
  662.  
  663.  
  664. CCCCoooommmmmmmmaaaannnndddd WWWWrrrriiiittttiiiinnnngggg((((3333TTTTccccllll))))                                    CCCCoooommmmmmmmaaaannnndddd WWWWrrrriiiittttiiiinnnngggg((((3333TTTTccccllll))))
  665.  
  666.  
  667.  
  668.      For more information on variable traces, consult the TTTTrrrraaaacccceeeeVVVVaaaarrrr(3) manual
  669.      page in the Berkeley Tcl distribution.
  670.  
  671. TTTTRRRRAAAACCCCIIIINNNNGGGG EEEEXXXXEEEECCCCUUUUTTTTIIIIOOOONNNN
  672.      Tcl has the ability to call C routines for every command it executes, up
  673.      to a specified depth of nesting levels.  The command TTTTccccllll____CCCCrrrreeeeaaaatttteeeeTTTTrrrraaaacccceeee
  674.      creates an execution trace; TTTTccccllll____DDDDeeeelllleeeetttteeeeTTTTrrrraaaacccceeee deletes it.
  675.  
  676.      Command tracing is used in Extended Tcl to implement the _c_m_d_t_r_a_c_e Tcl
  677.      command, a useful command for debugging Tcl applications.
  678.  
  679.      For complete information on execution tracing, please look at the
  680.      CCCCrrrrttttTTTTrrrraaaacccceeee(3) manual pages in the Berkeley Tcl distribution.
  681.  
  682. EEEEVVVVAAAALLLLUUUUAAAATTTTIIIINNNNGGGG TTTTCCCCLLLL EEEEXXXXPPPPRRRREEEESSSSSSSSIIIIOOOONNNNSSSS FFFFRRRROOOOMMMM CCCC
  683.      TTTTccccllll____EEEExxxxpppprrrrLLLLoooonnnngggg, TTTTccccllll____EEEExxxxpppprrrrDDDDoooouuuubbbblllleeee, TTTTccccllll____EEEExxxxpppprrrrBBBBoooooooollll, and TTTTccccllll____EEEExxxxpppprrrrSSSSttttrrrriiiinnnngggg can be
  684.      called to evaluate Tcl expressions from within a C routine.  Depending on
  685.      the routine called, the result is either a C _l_o_n_g, a _d_o_u_b_l_e, a boolean
  686.      (_i_n_t with a value of 0000 or _1), or a _c_h_a_r * (pointed to by _i_n_t_e_r_p->_r_e_s_u_l_t).
  687.  
  688.      For complete information on evaluating Tcl expressions from C, you are
  689.      invited to examine the EEEExxxxpppprrrrLLLLoooonnnngggg(3) manpage in the Berkeley Tcl
  690.      distribution.
  691.  
  692. PPPPAAAATTTTTTTTEEEERRRRNNNN MMMMAAAATTTTCCCCHHHHIIIINNNNGGGG
  693.      The TTTTccccllll____SSSSttttrrrriiiinnnnggggMMMMaaaattttcccchhhh function can be called to see if a string matches a
  694.      specified pattern.  TTTTccccllll____SSSSttttrrrriiiinnnnggggMMMMaaaattttcccchhhh is called by the Tcl _s_t_r_i_n_g _m_a_t_c_h
  695.      command, so the format for patterns is identical.  The pattern format is
  696.      similar to the one used by the C-shell; ssssttttrrrriiiinnnngggg(n) describes this format.
  697.  
  698.      More information about TTTTccccllll____SSSSttttrrrriiiinnnnggggMMMMaaaattttcccchhhh is available in the SSSSttttrrrrMMMMaaaattttcccchhhh(3)
  699.      manpage in the Berkeley Tcl distribution.
  700.  
  701. RRRREEEEGGGGUUUULLLLAAAARRRR EEEEXXXXPPPPRRRREEEESSSSSSSSIIIIOOOONNNN PPPPAAAATTTTTTTTEEEERRRRNNNN MMMMAAAATTTTCCCCHHHHIIIINNNNGGGG
  702.      TTTTccccllll____RRRReeeeggggEEEExxxxppppMMMMaaaattttcccchhhh can be called to determine whether a string matches a
  703.      regular expression.  TTTTccccllll____RRRReeeeggggEEEExxxxppppMMMMaaaattttcccchhhh is used internally by the _r_e_g_e_x_p Tcl
  704.      command.
  705.  
  706.      For more information on this function, please consult the RRRReeeeggggEEEExxxxpppp(3)
  707.      manpage in the Berkeley Tcl distribution.
  708.  
  709. MMMMAAAANNNNIIIIPPPPUUUULLLLAAAATTTTIIIINNNNGGGG TTTTCCCCLLLL LLLLIIIISSSSTTTTSSSS FFFFRRRROOOOMMMM CCCC EEEEXXXXTTTTEEEENNNNSSSSIIIIOOOONNNNSSSS
  710.      The C extension writer often needs to create, manipulate and decompose
  711.      Tcl lists.  TTTTccccllll____SSSSpppplllliiiittttLLLLiiiisssstttt parses a list into an _a_r_g_v and _a_r_g_c like to the
  712.      way command-line arguments are passed to a Tcl extension.  TTTTccccllll____MMMMeeeerrrrggggeeee,
  713.      likewise, creates a single string (pointer to a _c_h_a_r *) from an _a_r_g_v and
  714.      _a_r_g_c.
  715.  
  716.      Two routines, TTTTccccllll____SSSSccccaaaannnnEEEElllleeeemmmmeeeennnntttt and TTTTccccllll____CCCCoooonnnnvvvveeeerrrrttttEEEElllleeeemmmmeeeennnntttt, do most of the work
  717.      of TTTTccccllll____MMMMeeeerrrrggggeeee, and may also be of use to the C programmer.
  718.  
  719.  
  720.  
  721.  
  722.  
  723.                                                                        PPPPaaaaggggeeee 11111111
  724.  
  725.  
  726.  
  727.  
  728.  
  729.  
  730. CCCCoooommmmmmmmaaaannnndddd WWWWrrrriiiittttiiiinnnngggg((((3333TTTTccccllll))))                                    CCCCoooommmmmmmmaaaannnndddd WWWWrrrriiiittttiiiinnnngggg((((3333TTTTccccllll))))
  731.  
  732.  
  733.  
  734.      For more information on these commands, please consult the SSSSpppplllliiiittttLLLLiiiisssstttt(3)
  735.      manual page in the Berkeley Tcl distribution.
  736.  
  737. CCCCOOOONNNNCCCCAAAATTTTEEEENNNNAAAATTTTIIIINNNNGGGG SSSSTTTTRRRRIIIINNNNGGGGSSSS
  738.      TTTTccccllll____CCCCoooonnnnccccaaaatttt concatenates zero or more strings into a single string.  The
  739.      strings are space-separated.  TTTTccccllll____CCCCoooonnnnccccaaaatttt works like _T_c_l__M_e_r_g_e, except
  740.      that TTTTccccllll____CCCCoooonnnnccccaaaatttt does not attempt to make the resulting string into a
  741.      valid Tcl list.
  742.  
  743.      TTTTccccllll____CCCCoooonnnnccccaaaatttt is documented in the CCCCoooonnnnccccaaaatttt(3) manpage in the Berkeley Tcl
  744.      distribution.
  745.  
  746. DDDDEEEETTTTEEEECCCCTTTTIIIINNNNGGGG WWWWHHHHEEEETTTTHHHHEEEERRRR OOOORRRR NNNNOOOOTTTT YYYYOOOOUUUU HHHHAAAAVVVVEEEE
  747.      C routines that collect data to form a command to be passed to _T_c_l__E_v_a_l
  748.      often need a way to tell whether they have a complete command already or
  749.      whether they need more data.  (Programs that read typed-in Tcl input such
  750.      as Tcl shells need this capability.)  TTTTccccllll____CCCCoooommmmmmmmaaaannnnddddCCCCoooommmmpppplllleeeetttteeee can be used to
  751.      tell whether or not you have a complete command.
  752.  
  753.      For more information examine CCCCmmmmddddCCCCmmmmpppplllltttt(3) in the Berkeley Tcl
  754.      distribution.
  755.  
  756. RRRREEEECCCCOOOORRRRDDDDIIIINNNNGGGG CCCCOOOOMMMMMMMMAAAANNNNDDDDSSSS FFFFOOOORRRR CCCCOOOOMMMMMMMMAAAANNNNDDDD HHHHIIIISSSSTTTTOOOORRRRYYYY
  757.      Tcl has a history mechanism that is accessed from Tcl through the _h_i_s_t_o_r_y
  758.      command.  To propagate commands into the command history, your extension
  759.      should call _T_c_l__R_e_c_o_r_d_A_n_d_E_v_a_l.  This command works just like _T_c_l__E_v_a_l,
  760.      except that it records the command as well as executing it.
  761.  
  762.      _T_c_l__R_e_c_o_r_d_A_n_d_E_v_a_l should only be called with user-entered top-level
  763.      commands, since the history mechanism exists to allow the user to easily
  764.      access, edit and reissue previously issued commands.
  765.  
  766.      For complete information on this function, please examine the
  767.      RRRReeeeccccoooorrrrddddEEEEvvvvaaaallll.3 manual page in the Berkeley Tcl distribution.
  768.  
  769. CCCCOOOONNNNVVVVEEEERRRRTTTTIIIINNNNGGGG FFFFLLLLOOOOAAAATTTTIIIINNNNGGGG PPPPOOOOIIIINNNNTTTT VVVVAAAALLLLUUUUEEEESSSS TTTTOOOO SSSSTTTTRRRRIIIINNNNGGGGSSSS
  770.      TTTTccccllll____PPPPrrrriiiinnnnttttDDDDoooouuuubbbblllleeee converts a C _d_o_u_b_l_e into an ASCII string.  It ensures
  771.      that the string output will continue to be interpreted as a floating
  772.      point number, rather than an integer, by always putting a ``.'' or ``e''
  773.      into the string representing the number.  The precision of the output
  774.      string is controlled by the Tcl ttttccccllll____pppprrrreeeecccciiiissssiiiioooonnnn variable.
  775.  
  776.      For complete information on _T_c_l__P_r_i_n_t_D_o_u_b_l_e, examine PPPPrrrriiiinnnnttttDDDDbbbbllll(3) in the
  777.      Berkeley Tcl distribution.
  778.  
  779. CCCCRRRREEEEAAAATTTTIIIINNNNGGGG CCCCHHHHIIIILLLLDDDD PPPPRRRROOOOCCCCEEEESSSSSSSSEEEESSSS AAAANNNNDDDD PPPPIIIIPPPPEEEELLLLIIIINNNNEEEESSSS FFFFRRRROOOOMMMM
  780.      TTTTccccllll____CCCCrrrreeeeaaaatttteeeePPPPiiiippppeeeelllliiiinnnneeee is a useful procedure for spawning child processes.
  781.      The child (or pipeline of children) can have its standard input, output
  782.      and error redirected from files, variables or pipes.  To understand the
  783.      meaning of the redirection symbols understood by this function, look at
  784.      the eeeexxxxeeeecccc(n) Tcl command.  For complete information on TTTTccccllll____CCCCrrrreeeeaaaatttteeeePPPPiiiippppeeeelllliiiinnnneeee,
  785.      please examine CCCCrrrrttttPPPPiiiippppeeeelllliiiinnnn(3).
  786.  
  787.  
  788.  
  789.                                                                        PPPPaaaaggggeeee 11112222
  790.  
  791.  
  792.  
  793.  
  794.  
  795.  
  796. CCCCoooommmmmmmmaaaannnndddd WWWWrrrriiiittttiiiinnnngggg((((3333TTTTccccllll))))                                    CCCCoooommmmmmmmaaaannnndddd WWWWrrrriiiittttiiiinnnngggg((((3333TTTTccccllll))))
  797.  
  798.  
  799.  
  800. AAAACCCCCCCCEEEESSSSSSSSIIIINNNNGGGG TTTTCCCCLLLL FFFFIIIILLLLEEEEHHHHAAAANNNNDDDDLLLLEEEESSSS FFFFRRRROOOOMMMM CCCC
  801.      Files opened from your C code can be made visible to Tcl code via the
  802.      TTTTccccllll____EEEEnnnntttteeeerrrrFFFFiiiilllleeee function.  Likewise, Tcl filehandles passed to your C
  803.      extension can be translated to a Posix _F_I_L_E * structure using the
  804.      TTTTccccllll____GGGGeeeettttOOOOppppeeeennnnFFFFiiiilllleeee function.
  805.  
  806.      For complete explanations of these commands, please look at EEEEnnnntttteeeerrrrFFFFiiiilllleeee(3)
  807.      in the Berkeley Tcl distribution.
  808.  
  809.  
  810. MMMMAAAANNNNAAAAGGGGIIIINNNNGGGG BBBBAAAACCCCKKKKGGGGRRRROOOOUUUUNNNNDDDD PPPPRRRROOOOCCCCEEEESSSSSSSS TTTTEEEERRRRMMMMIIIINNNNAAAATTTTIIIIOOOONNNN AAAANNNNDDDD CCCCLLLLEEEEAAAANNNNUUUUPPPP
  811.      When a Posix system does a _f_o_r_k to create a new process, the process ID
  812.      of the child is returned to the caller.  After the child process exits,
  813.      its process table entry (and some other data associated with the process)
  814.      cannot be reclaimed by the operating system until a call to _w_a_i_t_p_i_d, or
  815.      one of a couple of other, similar system calls, has been made by the
  816.      parent process.
  817.  
  818.      The C extension writer who has created a subprocess, by whatever
  819.      mechanism, can turn over responsibility for detecting the processes'
  820.      termination and calling _w_a_i_t_p_i_d to obtain its exit status by calling
  821.      TTTTccccllll____DDDDeeeettttaaaacccchhhhPPPPiiiiddddssss.
  822.  
  823.      TTTTccccllll____RRRReeeeaaaappppDDDDeeeettttaaaacccchhhheeeeddddPPPPrrrrooooccccssss is the C routine that will detect the termination
  824.      of any processes turned over to Tcl, permitting the processes to be fully
  825.      reclaimed by the operating system.
  826.  
  827.      For complete information on these routines, please look at _D_e_t_a_c_h_P_i_d_s(_3)
  828.      in the Berkeley Tcl distribution.
  829.  
  830. FFFFOOOORRRR MMMMOOOORRRREEEE IIIINNNNFFFFOOOORRRRMMMMAAAATTTTIIIIOOOONNNN
  831.      In addition to the documentation referenced above, you can learn a lot by
  832.      studying the source code of the commands added by Tcl, Tk and Extended
  833.      Tcl.  The _c_o_m_p._l_a_n_g._t_c_l Usenet newsgroup is read by tens of thousands of
  834.      Tcl people, and is a good place to ask questions.  Finally, if you have
  835.      interactive Internet access, you can ftp to _f_t_p._a_u_d._a_l_c_a_t_e_l._c_o_m, the site
  836.      for contributed Tcl sources.  This site contains quite a few extensions,
  837.      applications, and so forth, including several object-oriented extension
  838.      packages.
  839.  
  840.  
  841.  
  842.  
  843.  
  844.  
  845.  
  846.  
  847.  
  848.  
  849.  
  850.  
  851.  
  852.  
  853.  
  854.  
  855.                                                                        PPPPaaaaggggeeee 11113333
  856.  
  857.  
  858.  
  859.